﻿/*******************************************************
* Copyright (c) 2018-2088, By XuXiang all rights reserved.
*
* FileName: ModuleBase.h
* Summary: 模块基类。
*
* Author: XuXiang
* Date: 2024-04-10 14:21
*******************************************************/

#ifndef __ModuleBase_h__
#define __ModuleBase_h__

#include "../Macro.h"
#include "EventManager.h"
#include <vector>

namespace Competition
{
	class ServerBase;
	class NetManagerBase;	
	class StorageManager;
	class MySQLWrap;
	class ModuleConfig;
	struct NetDataItem;

	namespace Net
	{
		class NetMessage;
	}

	class ModuleBase
	{
	public:
		ModuleBase();
		virtual ~ModuleBase();

		//注册网络消息
		virtual void RegisterNetMessage(NetManagerBase *pMgr) = 0;

		//注册存储消息
		virtual void RegisterStorageMessage(StorageManager* pMgr) = 0;

		//初始化配置列表
		virtual void AddConfig(std::vector<ModuleConfig*> &cfgs) = 0;

		//初始化
		virtual void Init();

		//销毁
		virtual void Release();

		//帧更新 需要重写IsEnableUpdate返回true才启用
		virtual void OnUpdate(){}

		//是否启用帧Update
		virtual bool IsEnableUpdate() { return false; }

		//秒更新
		virtual void OnUpdatePerSecond(){}

		//获取服务
		static ServerBase* GetServer();

		//获取数据库
		static MySQLWrap* GetMySQL();

		//发送网络消息 rid:角色编号
		static void SendNet(Int64 rid, int command, Net::NetMessage *msg);

		//存储请求
		static void RequestStorage(Int64 rid, int command, Net::NetMessage* msg);

		//存储回复
		static void ResponseStorage(Int64 rid, int command, Net::NetMessage* msg);
	};
}

#endif